package com.kaiyidiannao.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.Order;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by mark on 2014/4/16.
 * 订单
 */
public class OrderCheckAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;
    private List<Order> list = new ArrayList<Order>();

    public OrderCheckAdapter(Context context, List<Order> list) {
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView orderNum = null;
        TextView orderTime = null;
        TextView isSend = null;
        TextView orderTotal = null;
        Order order = list.get(position);
        if (convertView==null)
        {
            convertView=layoutInflater.inflate(R.layout.order_check_item,null);
        }
        orderNum = (TextView)convertView.findViewById(R.id.orderNum);
        orderTime = (TextView)convertView.findViewById(R.id.orderTime);
        isSend = (TextView)convertView.findViewById(R.id.isSend);
        orderTotal = (TextView)convertView.findViewById(R.id.orderTotal);
        orderNum.setText(order.getOrderid());

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String date = sdf.format(new Date(Integer.parseInt(order.getAddtime())* 1000L));
        orderTime.setText(date);
        if(order.getStatus().equals("0")){
            isSend.setText("等待付款");
            isSend.setTextColor(Color.RED);
        }else if(order.getStatus().equals("1")){
            isSend.setTextColor(Color.RED);
            isSend.setText("等待发货");
        }else if(order.getStatus().equals("2")){
            isSend.setTextColor(Color.GREEN);
            isSend.setText("交易成功");
        }

        orderTotal.setText(order.getAmount());

        return convertView;
    }
}
